﻿Imports DotNetNuke.Common.Utilities
Imports DotNetNuke.Entities.Content
Imports DotNetNuke.Entities.Content.Common
Imports DotNetNuke.Entities.Content.Taxonomy
Imports System.Text

<TestClass()>
Public Class ContactContentTests

#Region "---TestDeleteContentItem_NullContentItemID---"
    <TestMethod()>
    Public Sub TestDeleteContentItem_NullContentItemID()
        Dim testItemController As New TestDotNetNukeContentItemController
        Dim testTerms As New TestContactTerms
        Dim testContact As New DotNetNuke.Modules.GeminorumSoftwareContacts.Contact
        Dim target As New DotNetNuke.Modules.GeminorumSoftwareContacts.ContactContent(testItemController, testTerms, Nothing)

        testContact.ContentItemId = Null.NullInteger

        target.DeleteContentItem(testContact)

        Assert.AreEqual(0, testItemController.ContentItemID_PassedTo_GetContentItem)
    End Sub
#End Region
#Region "---TestDeleteContentItem_WithContentItemID---"
    <TestMethod()>
    Public Sub TestDeleteContentItem_WithContentItemID_ReturnNullFromGetContentItem()
        Dim testItemController As New TestDotNetNukeContentItemController
        Dim testTerms As New TestContactTerms
        Dim testContact As New DotNetNuke.Modules.GeminorumSoftwareContacts.Contact
        Dim target As New DotNetNuke.Modules.GeminorumSoftwareContacts.ContactContent(testItemController, testTerms, Nothing)

        testContact.ContentItemId = 1000

        target.DeleteContentItem(testContact)

        Assert.AreEqual(1000, testItemController.ContentItemID_PassedTo_GetContentItem)
        Assert.IsNull(testTerms.ContentItem_PassedTo_RemoveContactTerms)
        Assert.IsNull(testItemController.ContentItem_PassedTo_DeleteContentItem)
    End Sub
#End Region
#Region "---TestDeleteContentItem_WithContentItemID_ContentItemReturned---"
    <TestMethod()>
    Public Sub TestDeleteContentItem_WithContentItemID_ContentItemReturned()
        Dim testItemController As New TestDotNetNukeContentItemController
        Dim testTerms As New TestContactTerms
        Dim testContact As New DotNetNuke.Modules.GeminorumSoftwareContacts.Contact
        Dim target As New DotNetNuke.Modules.GeminorumSoftwareContacts.ContactContent(testItemController, testTerms, Nothing)

        testItemController.ContentItemToReturnFromGetContentItem = New DotNetNuke.Entities.Content.ContentItem
        testContact.ContentItemId = 1000

        target.DeleteContentItem(testContact)

        Assert.AreEqual(1000, testItemController.ContentItemID_PassedTo_GetContentItem)
        Assert.IsNotNull(testTerms.ContentItem_PassedTo_RemoveContactTerms)
        Assert.IsNotNull(testItemController.ContentItem_PassedTo_DeleteContentItem)
    End Sub
#End Region

#Region "---TestUpdateContentItem_NullReturnedFromGetContentItem---"
    <TestMethod()>
    Public Sub TestUpdateContentItem_NullReturnedFromGetContentItem()
        Dim testItemController As New TestDotNetNukeContentItemController
        Dim testTerms As New TestContactTerms
        Dim testContact As New DotNetNuke.Modules.GeminorumSoftwareContacts.Contact
        Dim target As New DotNetNuke.Modules.GeminorumSoftwareContacts.ContactContent(testItemController, testTerms, Nothing)

        target.UpdateContentItem(testContact, 1000)

        Assert.IsNull(testItemController.ContentItem_PassedTo_UpdateContentItem)
    End Sub
#End Region
#Region "---TestUpdateContentItem_ContentItemReturnedFromGetContentItem---"
    <TestMethod()>
    Public Sub TestUpdateContentItem_ContentItemReturnedFromGetContentItem()
        Dim testItemController As New TestDotNetNukeContentItemController
        Dim testTerms As New TestContactTerms
        Dim testContact As New DotNetNuke.Modules.GeminorumSoftwareContacts.Contact
        Dim target As New DotNetNuke.Modules.GeminorumSoftwareContacts.ContactContent(testItemController, testTerms, Nothing)

        testItemController.ContentItemToReturnFromGetContentItem = New DotNetNuke.Entities.Content.ContentItem
        testContact.Name = "Name"

        target.UpdateContentItem(testContact, 1000)

        Assert.IsNotNull(testItemController.ContentItem_PassedTo_UpdateContentItem)
        Assert.AreEqual("Name", testItemController.ContentItem_PassedTo_UpdateContentItem.Content)
        Assert.AreEqual(1000, testItemController.ContentItem_PassedTo_UpdateContentItem.TabID)
        Assert.IsNotNull(testTerms.ContentItem_PassedTo_ManageContactTerms)
        Assert.IsNotNull(testTerms.Contact_PassedTo_ManageContactTerms)
    End Sub
#End Region

#Region "---TestCreateContentItem---"
    <TestMethod()>
    Public Sub TestCreateContentItem()
        Dim testItemController As New TestDotNetNukeContentItemController
        Dim testTerms As New TestContactTerms
        Dim testContentTypeController As New TestContentTypeController
        Dim testContact As New DotNetNuke.Modules.GeminorumSoftwareContacts.Contact
        Dim target As New DotNetNuke.Modules.GeminorumSoftwareContacts.ContactContent(testItemController, testTerms, testContentTypeController)

        testContact.ID = 9888
        testContact.ModuleID = 7888
        testContact.Name = "Name"

        Dim contentItem As DotNetNuke.Entities.Content.ContentItem = target.CreateContentItem(testContact, 1000)

        Assert.IsNotNull(testTerms.ContentItem_PassedTo_ManageContactTerms)
        Assert.IsNotNull(testTerms.Contact_PassedTo_ManageContactTerms)
        Assert.AreEqual("Name", contentItem.Content)
        Assert.AreEqual(-1, contentItem.ContentTypeId)
        Assert.AreEqual(False, contentItem.Indexed)
        Assert.AreEqual("tid=9888", contentItem.ContentKey)
        Assert.AreEqual(7888, contentItem.ModuleID)
        Assert.AreEqual(1000, contentItem.TabID)
        Assert.AreEqual(-1, contentItem.ContentTypeId)
    End Sub
#End Region

#Region "---TestDotNetNukeContentItemController---"
    Private Class TestDotNetNukeContentItemController
        Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentItemController

        Public Function AddContentItem(contentIteem As DotNetNuke.Entities.Content.ContentItem) As Integer Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentItemController.AddContentItem

        End Function

        Public Property ContentItem_PassedTo_DeleteContentItem As DotNetNuke.Entities.Content.ContentItem
        Public Sub DeleteContentItem(contentItem As DotNetNuke.Entities.Content.ContentItem) Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentItemController.DeleteContentItem
            ContentItem_PassedTo_DeleteContentItem = contentItem
        End Sub

        Public Property ContentItemID_PassedTo_GetContentItem As Integer
        Public Property ContentItemToReturnFromGetContentItem As DotNetNuke.Entities.Content.ContentItem
        Public Function GetContentItem(contentItemId As Integer) As DotNetNuke.Entities.Content.ContentItem Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentItemController.GetContentItem
            ContentItemID_PassedTo_GetContentItem = contentItemId
            Return ContentItemToReturnFromGetContentItem
        End Function

        Public Property ContentItem_PassedTo_UpdateContentItem As DotNetNuke.Entities.Content.ContentItem
        Public Sub UpdateContentItem(contentItem As DotNetNuke.Entities.Content.ContentItem) Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentItemController.UpdateContentItem
            ContentItem_PassedTo_UpdateContentItem = contentItem
        End Sub
    End Class
#End Region
#Region "---TestContactTerms---"
    Private Class TestContactTerms
        Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iTerms(Of DotNetNuke.Modules.GeminorumSoftwareContacts.Contact)

        Public Property Contact_PassedTo_ManageContactTerms As DotNetNuke.Modules.GeminorumSoftwareContacts.Contact
        Public Property ContentItem_PassedTo_ManageContactTerms As DotNetNuke.Entities.Content.ContentItem
        Public Sub ManageContactTerms(obj As DotNetNuke.Modules.GeminorumSoftwareContacts.Contact, objContent As DotNetNuke.Entities.Content.ContentItem) Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iTerms(Of DotNetNuke.Modules.GeminorumSoftwareContacts.Contact).ManageContactTerms
            Contact_PassedTo_ManageContactTerms = obj
            ContentItem_PassedTo_ManageContactTerms = objContent
        End Sub

        Public Property ContentItem_PassedTo_RemoveContactTerms As DotNetNuke.Entities.Content.ContentItem
        Public Sub RemoveContactTerms(objContent As DotNetNuke.Entities.Content.ContentItem) Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iTerms(Of DotNetNuke.Modules.GeminorumSoftwareContacts.Contact).RemoveContactTerms
            ContentItem_PassedTo_RemoveContactTerms = objContent
        End Sub
    End Class
#End Region
#Region "---TestContentTypeController---"
    Private Class TestContentTypeController
        Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentTypeController

        Public Function AddContentType(contentType As DotNetNuke.Entities.Content.ContentType) As Integer Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentTypeController.AddContentType
            Return -1
        End Function

        Public Function GetContentTypes() As System.Linq.IQueryable(Of DotNetNuke.Entities.Content.ContentType) Implements DotNetNuke.Modules.GeminorumSoftwareContacts.iDotNetNukeContentTypeController.GetContentTypes
            Return (From c In New List(Of DotNetNuke.Entities.Content.ContentType)).AsQueryable
        End Function
    End Class
#End Region
End Class